<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<RMH.Entities.Patient>" %>
<%@ Import Namespace="RMH.Entities"%>
<%@ Import Namespace="RMH"%>
<%@ Import Namespace="RMH.Web.Controllers"%>
<%@ Import Namespace="Microsoft.Web.Mvc"%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

       
<% if (Model.Id > 0)
   { %>
    <h2>Edit Patient - <%= Html.Encode(Model.LastName) + ", " + Html.Encode(Model.FirstName)%></h2>
<% }
   else
   { %>
    <h2>Create Patient</h2>
<% } %>

                
    <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>
    <% using (Html.BeginForm()) {%>
                    
    <%= Html.Hidden("Id", Model.Id) %>    
    <input type="text" name="patient.FirstName" />
    <h3>Patient Info:</h3>
    <%Html.RenderPartial("_Person", Model, ViewData); %>
    <table class="info">
            <tr>
            <td><label for="DateOfBirth">Date of Birth:</label></td>
            <td>                       
                <input type="text" name="DateOfBirth" 
                    value='<%= String.Format("{0:d}", Model.DateOfBirth) %>'
                    class="date" />
                <%= Html.ValidationMessage("DateOfBirth", "*") %>
            </td>
            <td>
                <label for="DateOfDeath">
                    Date of Death:</label>
            </td>
            <td>
                <input type="text" name="DateOfDeath" 
                    value='<%= String.Format("{0:d}", Model.DateOfDeath) %>'
                    class="date" />
                <%= Html.ValidationMessage("DateOfDeath", "*") %>
            </td>
        </tr>
    </table>        
    <div><h3>Diagnosis:</h3>
        <p>
            <% Html.RenderPartial("_Diagnosis", Model.Diagnoses); %>
            <% Html.RenderAction<DiagnosisController>(s=>s.DropDown()); %>
        </p>  
    </div>
    
    <h3>Support People</h3>

    <!--TODO: better default search -->
    <div id="relationshipList">
    <!-- TODO: put this somewhere else LOOP THROUGH MODELS AND WRITE OUT JS-->
    <script type="text/javascript">
        $(function() {
            <% foreach(var relationship in Model.Relationships) {%>
                   rmh.addSupportPerson(
                    <%= relationship.SupportPerson.Id %>, 
                    "<%= relationship.SupportPerson.GetFullName().Replace("\"", String.Empty) %>", 
                    <%= relationship.Type.ToInt().ToString() %>, 
                    '<%= relationship.Type.ToString() %>');
            <%} %>
        });
    </script>
    </div>
    
    <div id="supportPersonContainer">
   
    <% Html.RenderAction<SupportPersonController>(s=>s.DropDown(String.Empty, Model.LastName)); %>
                    
    </div>
    <% Html.RenderPartial("_Address", Model); %>
  
    <input type="submit" value="Save" />
    <% } %>
    <%= Html.ClientSideValidation<Patient>("patient")%> 
    
    
</asp:Content>
